package com.itheima.app.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.cloud.dubbo.util.JSONUtils;
import com.alibaba.fastjson.JSON;
import com.itheima.app.manager.SoulTestManager;
import com.itheima.domain.db.Answer;
import com.itheima.domain.db.Answers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class SoulTestController {

    @Autowired
    private SoulTestManager soulTestManager;
//显示tiku
    @GetMapping("/testSoul")
    public ResponseEntity testSoul() {
        return soulTestManager.testSoul();

    }

    //提交结果
    @PostMapping("/testSoul")
    public ResponseEntity commit(@RequestBody Map answers) {
        Answers answers1 = JSON.parseObject(JSON.toJSONString(answers), Answers.class);
        List<Answer> answers2 = answers1.getAnswers();
        System.out.println(answers2);

        return soulTestManager.commit(answers2);
    }

    @GetMapping("/testSoul/report/{id}")
    public ResponseEntity findReport(@PathVariable String id) {

        return soulTestManager.findReport(Integer.parseInt(id));
    }

}
